package com.cskaoyan.market.controller.wx;

import com.cskaoyan.market.db.domain.MarketUser;
import com.cskaoyan.market.service.WxHomeService;
import com.cskaoyan.market.util.ResponseUtil;
import com.cskaoyan.market.vo.WxHomeIndexVo;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.mgt.SecurityManager;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.ExecutionException;

@RestController
@RequestMapping("wx/home")
public class WxHomeController {

    @Autowired
    WxHomeService wxHomeService;

    @Autowired
    SecurityManager securityManager;

    @GetMapping("index")
    public Object index() throws ExecutionException, InterruptedException {

        SecurityUtils.setSecurityManager(securityManager);
        Subject subject = SecurityUtils.getSubject();
        MarketUser user = (MarketUser) subject.getPrincipal();
        WxHomeIndexVo wxHomeIndexVo = wxHomeService.index(user);
        return ResponseUtil.ok(wxHomeIndexVo);
    }
}
